﻿using Microsoft.Practices.Unity;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Rhino.Mocks;
using TestByWire.Factories.StubbingStrategies;

namespace TestByWire.Test.Factories.StubbingStrategies
{
    [TestClass]
    public class StubbingStrategyTest
    {
        private IUnityContainer _container;
        private StubbingStrategy _activatorStrategy;
        private PipelineSettings _pipelineSettings;

        [TestInitialize]
        public void PerTestSetup()
        {
            _container = new UnityContainer();

            _pipelineSettings = new PipelineSettings();
            _container.RegisterInstance(_pipelineSettings);

            _activatorStrategy = new StubbingStrategy(_container);
        }

        [TestMethod]
        public void CanHandleTypeMustReturnTrueIfTypeIsPublicInterface()
        {
            bool result = _activatorStrategy.CanHandleType(typeof(Fakes.ICalculator), null);

            Assert.IsTrue(result);
        }

        [TestMethod]
        public void CanHandleTypeMustReturnFalseIfTypeIsString()
        {
            bool result = _activatorStrategy.CanHandleType(typeof(string), null);

            Assert.IsFalse(result);
        }

        [TestMethod]
        public void CanHandleTypeMustReturnFalseIfTypeIsOnDoNotStubList()
        {
            _pipelineSettings.DoNotStubList.Add(new DoNotStub(typeof(RealType), null));

            bool result = _activatorStrategy.CanHandleType(typeof(RealType), null);

            Assert.IsFalse(result);
        }

        [TestMethod]
        public void MustReturnTrueForRegisterOnContainer()
        {
            Assert.IsTrue(_activatorStrategy.RegisterOnContainer);
        }

        internal class RealType
        {
        }
    }
}
